<template>
	<view>
		{{timestr}}
	</view>
</template>

<script>
	export default {
		props: {
			countnum: Number
		},
		data() {
			return {
				timenums: '',
				timestr: '',
				timer: null
			}
		},
		created() {
			this.timenums = this.countnum
			if (this.timenums > 0) {
				this.timer = setInterval(() => {
					this.timenums--
				}, 1000)
			}
		},
		watch: {
			timenums(nval) {
				this.setCountDow(nval)
			}
		},
		beforeDestroy() {
			clearInterval(this.timer)
		},
		methods: {
			setCountDow(num) {
				if (num == 0) {
					clearInterval(this.timer)
					this.$emit('countDown')
				}
				let hour;
				let minutes;
				let secondtrue;
				if (num < 3600) {
					hour = 0;
					if (num < 60) {
						minutes = 0;
						secondtrue = num;
					} else {
						minutes = Math.floor(num / 60);
						secondtrue = num - minutes * 60;
					}
				} else {
					hour = Math.floor(num / 3600);
					if (num - hour * 3600 < 60) {
						minutes = 0;
						secondtrue = num - hour * 3600;
					} else {
						minutes = Math.floor((num - hour * 3600) / 60);
						secondtrue = num - hour * 3600 - minutes * 60;
					}
				}

				this.timestr =
					`${hour<10?('0'+hour):hour}:${minutes<10?('0'+minutes):minutes}:${secondtrue<10?('0'+secondtrue):secondtrue}`
			}
		}
	}
</script>

<style>
</style>